﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Clipper.BLL.DataBaseBLL
{
   public class CupDetectResultInfomation
    {
        Clipper.DAL.CupDetectResultInformation dal = new DAL.CupDetectResultInformation();

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(string strWhere)
        //      {
        //          return dal.GetAllList(strWhere);
        //      }

        //根据id删除
        public bool DeleteCupDetectResultById(Model.DataBaseModel.CupDetectResultInformation model)
        {
            return dal.Delete(model.Id);
        }
        public ObservableCollection<Model.DataBaseModel.CupDetectResultInformation> GetModelList()
        {
            DataSet ds = dal.GetAllList("");
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
		/// 增加一条数据
		/// </summary>
        public bool Add(Model.DataBaseModel.CupDetectResultInformation model)
        {
            return dal.Add(model);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public ObservableCollection<Model.DataBaseModel.CupDetectResultInformation> DataTableToList(DataTable dt)
        {
            ObservableCollection<Clipper.Model.DataBaseModel.CupDetectResultInformation> modelList = new ObservableCollection<Clipper.Model.DataBaseModel.CupDetectResultInformation>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Clipper.Model.DataBaseModel.CupDetectResultInformation model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        //model.SampleInfo = mSampleBll.GetModel(model.SampleID);
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得检测数据
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="id"></param>
        /// <param name="detectItem"></param>
        /// <param name="exception"></param>
        /// <param name="detecting"></param>
        /// <param name="detected"></param>
        /// <returns></returns>
        public ObservableCollection<Model.DataBaseModel.CupDetectResultInformation> GetCupDetectResultInformation
            (string start, string end, int? sampleStart, int? sampleEnd, string detectItem, bool exception)
        {
            string strWhere = "";
            if (start != null && end != null)
            {
                strWhere += " detectTime>='" + start + "' and detectTime<='" + end + "'";
            }
            if (sampleStart != null && sampleEnd != null)
            {
                strWhere += " and sampleInfoID>=" + sampleStart + " and sampleInfoID<=" + sampleEnd;
            }
            if (detectItem != null)
            {
                strWhere += " and detectItem='" + detectItem + "'";
            }
            if (exception)
            {
                strWhere += " and detectResult=1";
            }
            else
            {

            }
            if (strWhere.IndexOf(" and") == 0)
            {
                strWhere = strWhere.Substring(4);
            }
            ObservableCollection<Model.DataBaseModel.CupDetectResultInformation> modelList = GetModelList(strWhere);
            return modelList;
        }
        /// <summary>
        /// 获得数据列表5555
        /// </summary>
        public ObservableCollection<Clipper.Model.DataBaseModel.CupDetectResultInformation> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetAllList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }





    }
}
